package com.ichir.projects.uiframework.tests.mocks;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Map;

import javax.swing.JButton;
import javax.swing.JDialog;

import com.ichir.projects.uiflow.AbstractUiView;
import com.ichir.projects.uiflow.ApplicationContext;

/**
 * 
 * @author mahieddine_ichir
 */
public class View1 extends AbstractUiView {

	private JDialog dialog;
	
	@Override
	public void initializeView(ApplicationContext context, Map<String, Object> attributes) {
		System.out.println(">> initialize view 1");
		dialog = new JDialog();
		JButton comp = new JButton("Action 1");
		comp.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				fireEvent("act1");
			}
		});
		dialog.add(comp);
		
		dialog.setLocationRelativeTo(null);
	}

	@Override
	public void refreshView(ApplicationContext context, Map<String, Object> attributes) {
		System.out.println(">> refresh view 1");
	}

	@Override
	public void showView(ApplicationContext context, Map<String, Object> attributes) {
		dialog.setVisible(true);
	}

	@Override
	public void disposeView(ApplicationContext context, Map<String, Object> attributes) {
		System.out.println(">> dispose view");
		dialog.dispose();
	}
}
